package com.googlecode.particlesys.templates;

import java.awt.Color;

import com.googlecode.particlesys.objects.AbstractEmitter;
import com.googlecode.particlesys.objects.Particle;
import com.googlecode.particlesys.objects.Seeker;

public class TargetPosition extends AbstractEmitter implements Seeker {
	
	private int focusX = 100;
	private int focusY = 100;

	public TargetPosition(int x, int y){
		super(7, 7, x, y, 100, 0);
		super.setRate(17);
	}

	@Override
	public Particle getNextParticle(){
		Particle p = new Particle(Color.WHITE, width, height);
		p.setX(x);
		p.setY(y);
		p.setSpeed(5);
		p.setSeeker(this);
		p.setLife(distance(x, y, focusX, focusY)/4);	
		return p;
	}
	
	public double calculateAngle(int x, int y){
		return 360-(Math.atan2(focusY-y, focusX-x))*(180D/Math.PI);
	}
	
	private static int distance(final int x1, final int y1, final int x2, final int y2){
		return (int) Math.sqrt(sq(x2 - x1) + sq(y2 - y1));
	}
	
	private static int sq(final int i){
		return i*i;
	}
}